﻿# 指定CMake最低版本要求
cmake_minimum_required(VERSION 3.5)

# 添加CMake模块路径
list(APPEND CMAKE_MODULE_PATH "D:/Workshop/QT/Tools/CMake_64/share/cmake-3.27/Modules")

# 设置Qt安装路径
set(CMAKE_PREFIX_PATH "D:/Workshop/QT/6.6.2/mingw_64")

# 定义项目名称、版本和使用的语言
project(AikeMetting VERSION 0.1 LANGUAGES CXX)

# 启用Qt的自动化工具
set(CMAKE_AUTOUIC ON)  # 自动处理UI文件
set(CMAKE_AUTOMOC ON)  # 自动处理Q_OBJECT宏
set(CMAKE_AUTORCC ON)  # 自动处理资源文件


#设置编译器路径

set(CMAKE_CXX_COMPILER "D:/Workshop/QT/Tools/mingw1120_64/bin/g++.exe")

set(CMAKE_C_COMPILER "D:/Workshop/QT/Tools/mingw1120_64/bin/gcc.exe")



# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找并加载Qt组件
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core Multimedia MultimediaWidgets Concurrent Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core Multimedia MultimediaWidgets Concurrent Network)

# 设置项目根目录
set(AiKeMetting_Root_Dir ${CMAKE_CURRENT_LIST_DIR})
# message("ASIO2_ROOT_DIR = ${ASIO2_ROOT_DIR}")

#设置三方库
set(OpenSSL_INCLUDE_DIR D:/Workshop/QT/Tools/OpenSSLv3/Win_x64/include)
set(OpenSSL_CRYPT_LIB  D:/Workshop/QT/Tools/OpenSSLv3/Win_x64/lib/libcrypto.lib)
set(OpenSSL_SSL_LIB  D:/Workshop/QT/Tools/OpenSSLv3/Win_x64/lib/libssl.lib)
set(PROTOBUF_INCLUDE D:/Workshop/protobuf/include)
set(PROTOBUF_LIB D:/Workshop/protobuf/lib/libprotobuf.dll)
# file(GLOB_RECURSE ASIO2_FILES ${ASIO2_ROOT_DIR}/include/asio2/*.*)
# file (GLOB_RECURSE   ASIO_FILES  ${ASIO2_ROOT_DIR}/3rd/asio/*.*)
# file (GLOB_RECURSE CEREAL_FILES  ${ASIO2_ROOT_DIR}/3rd/cereal/*.*)

# include_directories (${ASIO2_ROOT_DIR}/3rd)
# include_directories (${ASIO2_ROOT_DIR}/3rd/openssl/include)
# include_directories (${ASIO2_ROOT_DIR}/include)




include_directories (${AiKeMetting_Root_Dir}/src)
include_directories(${OpenSSL_INCLUDE_DIR})
include_directories(${PROTOBUF_INCLUDE})

message(STATUS "ASIO2_ROOT_DIR is set to ${ASIO2_ROOT_DIR}")

#将项目名称放入到
set(TARGET_NAME AiKeMetting)



# set(OPENSSL_LIBS "libssl.lib;libcrypto.lib;Crypt32.lib;")

# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
#     set(ASIO2_LIBS_DIR ${ASIO2_ROOT_DIR}/3rd/openssl/prebuilt/windows/x64)
# elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
#     set(ASIO2_LIBS_DIR ${ASIO2_ROOT_DIR}/3rd/openssl/prebuilt/windows/x86)
# endif()

# 根据系统架构设置输出目录
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(AiKeMetting_EXES_DIR ${AiKeMetting_Root_Dir}/bin/x64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
    set(AiKeMetting_EXES_DIR ${AiKeMetting_Root_Dir}/bin/x86)
endif()

#设置输出库和可执行文件的路径
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY         ${AiKeMetting_EXES_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG   ${AiKeMetting_EXES_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${AiKeMetting_EXES_DIR})

# message("ASIO2_LIBS_DIR = ${ASIO2_LIBS_DIR}")
# message("ASIO2_EXES_DIR = ${ASIO2_EXES_DIR}")

# 设置系统库依赖
set(GENERAL_LIBS "ws2_32;mswsock;")

# 设置源文件列表
set(PROJECT_SOURCES
        main.cpp



)
add_definitions(-DOPENSSL_STATIC)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(${TARGET_NAME}
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
         # ${ASIO2_FILES}
        resource.qrc

        LICENSE
        src/loginWidget/logincode.cpp src/loginWidget/logincode.h src/loginWidget/settingwidget.cpp src/loginWidget/settingwidget.h
        src/settingWidget/about/aboutsoftware.cpp src/settingWidget/about/aboutsoftware.h src/settingWidget/audioWidget/audiowidget.cpp
        src/settingWidget/audioWidget/audiowidget.h src/settingWidget/audioWidget/bilateralaudioplay.cpp
        src/settingWidget/audioWidget/bilateralaudioplay.h src/settingWidget/audioWidget/customslider.cpp
        src/settingWidget/audioWidget/customslider.h src/settingWidget/audioWidget/mircrophoneiodevice.cpp
        src/settingWidget/audioWidget/mircrophoneiodevice.h src/settingWidget/audioWidget/myaudioplayer.cpp
        src/settingWidget/audioWidget/myaudioplayer.h src/settingWidget/audioWidget/myiodevice.cpp
        src/settingWidget/audioWidget/myiodevice.h src/settingWidget/commonSettingWidget/commonsettting.cpp
        src/settingWidget/commonSettingWidget/commonsettting.h src/settingWidget/NetWorkDetection/netdetectionwidget.cpp
        src/settingWidget/NetWorkDetection/netdetectionwidget.h src/settingWidget/videoWidget/videowidget.cpp
        src/settingWidget/videoWidget/videowidget.h src/utils/GenericaTask.h src/utils/signalcenter.cpp src/utils/signalcenter.h
        src/utils/util.cpp src/utils/util.h
        src/settingWidget/NetWorkDetection/loadingbutton.h src/settingWidget/NetWorkDetection/loadingbutton.cpp
        README.md
        src/settingWidget/NetWorkDetection/netfinishedwidget.h src/settingWidget/NetWorkDetection/netfinishedwidget.cpp
        src/loginWidget/mainloginwidget.h src/loginWidget/mainloginwidget.cpp
        src/loginWidget/phoneloginwidget.h src/loginWidget/phoneloginwidget.cpp
        src/loginWidget/phonepwdloginwidget.h src/loginWidget/phonepwdloginwidget.cpp
        src/loginWidget/hovertoolbutton.h src/loginWidget/hovertoolbutton.cpp

        src/videoConferenceClient/videoconferencingclient.h src/videoConferenceClient/videoconferencingclient.cpp

        src/socketFacotry/socketFactoryInterface.h
        src/socketFacotry/sslsocketfactory.h src/socketFacotry/sslsocketfactory.cpp
        src/utils/eccoperator.h src/utils/eccoperator.cpp
        src/utils/deleter.h src/utils/deleter.cpp
        src/utils/config.h
        src/utils/timeoperation.h src/utils/timeoperation.cpp
        src/utils/certificatemanager.h src/utils/certificatemanager.cpp
        src/utils/symmetricencryption.h src/utils/symmetricencryption.cpp


        CA/ca.crt
        src/Modules/ModuleInterface.cpp src/Modules/NetWorkInterface.h src/Modules/TcpNetwork.h src/Modules/TcpNework.cpp
        src/Modules/ModuleInterface.h
        src/Modules/applycertificateModule.h src/Modules/applycertificateModule.cpp
        src/Functionality/functionalityInterface.h
        src/Functionality/applycertificatefunctionality.h src/Functionality/applycertificatefunctionality.cpp
        src/Functionality/functionalityFactory.h
        src/Functionality/applycertificatefactory.h src/Functionality/applycertificatefactory.cpp
        src/utils/keymanager.h src/utils/keymanager.cpp
        src/Functionality/registerfunctionality.h src/Functionality/registerfunctionality.cpp
        src/Modules/registerLoginMessage.pb.cc src/Modules/registerLoginMessage.pb.h
        src/Modules/registermodule.h src/Modules/registermodule.cpp
        src/loginWidget/registerDialog.h src/loginWidget/registerDialog.cpp
        src/Functionality/registerfactory.h src/Functionality/registerfactory.cpp
        src/Functionality/loginfactory.h src/Functionality/loginfactory.cpp
        src/Functionality/loginfunctionality.h src/Functionality/loginfunctionality.cpp
        src/Modules/loginmodule.h src/Modules/loginmodule.cpp
        src/MainMettingWidget/screen.cpp src/MainMettingWidget/screen.h
        src/MainMettingWidget/mettingwidget.h src/MainMettingWidget/mettingwidget.cpp
        src/MainMettingWidget/VideoStreamingArchitecture.md
        src/MainMettingWidget/framelessRoundedwindow.h src/MainMettingWidget/framelessRoundedwindow.cpp
        src/MainMettingWidget/rightframegroupbox.h src/MainMettingWidget/rightframegroupbox.cpp
        src/MainMettingWidget/toolbargroupbox.h src/MainMettingWidget/toolbargroupbox.cpp
        src/MainMettingWidget/dategroupbox.h src/MainMettingWidget/dategroupbox.cpp


    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET AikeMetting APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(${TARGET_NAME} SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(${TARGET_NAME}
            ${PROJECT_SOURCES}
        )
    endif()
endif()


target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia Qt${QT_VERSION_MAJOR}::MultimediaWidgets Qt${QT_VERSION_MAJOR}::Concurrent)
target_link_libraries(${TARGET_NAME} PRIVATE ${GENERAL_LIBS} ${OpenSSL_CRYPT_LIB} ${OpenSSL_SSL_LIB} ${PROTOBUF_LIB})
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.AikeMetting)
endif()
set_target_properties(${TARGET_NAME} PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS ${TARGET_NAME}
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(${TARGET_NAME})
endif()

# 设置Qt core模块的include目录
set(Qt${QT_VERSION_MAJOR}_CORE_INCLUDE_DIRS ${CMAKE_PREFIX_PATH}/include/QtCore)
message("Qt${QT_VERSION_MAJOR}_CORE_INCLUDE_DIRS = ${Qt${QT_VERSION_MAJOR}_CORE_INCLUDE_DIRS}")
include_directories(${Qt${QT_VERSION_MAJOR}_CORE_INCLUDE_DIRS})
